package com.easybuy.service;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.easybuy.dao.UserMapper;
import com.easybuy.pojo.User;
import com.easybuy.util.PageBean;

@Transactional
@Service
public class UserServiceImpl implements UserService {

	@Resource
	private UserMapper userMapper;
	/**
	 * 注册时查询用户是否存在
	 */
	@Override
	public User selectUserExist(String loginName) {
		
		try {
			return userMapper.selectUserExist(loginName);
		} catch (Exception e) {
			e.printStackTrace();
			throw e;
		}
	
	}
	/***
	 * 注册时插入新用户
	 */
	@Override
	public int insertUser(User user) {
		try {
			return  userMapper.insert(user);
		} catch (Exception e) {
			e.printStackTrace();
			throw e;
		}
		
	}
	/**
	 * 用户登录
	 */
	@Override
	public User login(String loginName, String password) {
		try {
			return userMapper.login(loginName);
		} catch (Exception e) {
			e.printStackTrace();
			throw e;
		}
		
	}
	/**
	 * 用户数量
	 */
	@Override
	public int selectUserCount() {
		try {
			return userMapper.selectUserCount();
		} catch (Exception e) {
			e.printStackTrace();
			throw e;
		}
	}
	/**
	 *分页查询用户列表 
	 */
	@Override
	public List<User> selectUserByPage(Map<String, Object> params) {
		try {
			return userMapper.selectUserByPage(params);
		} catch (Exception e) {
			e.printStackTrace();
			throw e;
		}
	}
	
	@Override
	public int DelUerById(Integer id) {
		try {
			return userMapper.DelUerById(id);
		} catch (Exception e) {
			e.printStackTrace();
			throw e;
		}
		
	}
	
	@Override
	public int updateUser(User user) {
		try {
			return userMapper.updateUser(user);
		} catch (Exception e) {
			e.printStackTrace();
			throw e;
		}
	}
	@Override
	public User selectUserById(Integer id) {
		try {
			return userMapper.selectUserById(id);
		} catch (Exception e) {
			e.printStackTrace();
			throw e;
		}

	}
	@Override
	public User selectUserByUserId(Integer userId) {
		// TODO Auto-generated method stub
		return userMapper.selectUserByUserId(userId);
	}
	

}
